package com.i72;


import ch.qos.logback.classic.Level;
import com.i72.basic.annotation.AOPAnnotation;

import com.i72.basic.init.AOPInvoke;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.ClassFile;
import javassist.bytecode.ConstPool;
import javassist.bytecode.annotation.Annotation;
import javassist.bytecode.annotation.StringMemberValue;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;


/**
 * Hello world!
 */
@ComponentScan("com.i72")
//@AOPAnnotation(target = Service.class,invoke = AOPNotice.class)
@EnableAspectJAutoProxy
public class App {


    public static void main(String[] args) throws Exception {




        String value = "";
        //Class c = Double.class;



        //CtClass ccc = ClassPool.getDefault().makeAnnotation("org.springframework.stereotype.Component");


        /*
        ClassPool pool = ClassPool.getDefault();
        CtClass cc = pool.makeClass("com.i72.Test");

        ClassFile classFile = cc.getClassFile();
        ConstPool constpool = classFile.getConstPool();

        AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
        Annotation annotation = new Annotation("org.springframework.stereotype.Component", constpool);
        annotation.addMemberValue("value", new StringMemberValue("aaa",constpool));
        annotationsAttribute.setAnnotation(annotation);

        cc.getClassFile().addAttribute(annotationsAttribute);
        //return ctClass.toClass();

        CtMethod method = null;
        try {
            method = CtMethod.make(" public void say(){ System.out.println(\"Hello World!\"); } ", cc);
            cc.addMethod(method);
            Class type = cc.toClass();
            Object o = type.newInstance();

            Method[] methods = type.getMethods();

            methods[0].invoke(o,null);

            String vv = "";
        }catch (Exception e){

            String value = "";
        }*/






        ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(App.class);



        //logger.setLevel(Level.INFO);
        logger.debug("1hello world");


        System.out.println("Hello World!");



        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();

        annotationConfigApplicationContext.register(App.class);

        annotationConfigApplicationContext.refresh();


        Hello hello = annotationConfigApplicationContext.getBean(Hello.class);

        hello.say();

        hello.say2();


        Hello2 hello2 = annotationConfigApplicationContext.getBean(Hello2.class);

        hello2.say();

        hello2.say2();

    }
}
